package main

import (
	"IrisJwtCasbin/config"
	"IrisJwtCasbin/initApp"
	"IrisJwtCasbin/logger"
	"fmt"
	"github.com/kataras/iris"
	"io"
	"os"
	"time"
)

func main() {
	f := logger.NewLogFile()
	defer f.Close()
	logger.Info("启动......")
	api := initApp.NewApp()
	api.Logger().SetOutput(io.MultiWriter(f, os.Stdout))

	if config.Config.HTTPS {
		host := fmt.Sprintf("%s:%d", config.Config.Host, 443)
		if err := api.Run(iris.TLS(host, config.Config.Certpath, config.Config.Certkey)); err != nil {
			fmt.Println(err)
		}
	} else {
		if err := api.Run(
			iris.Addr(fmt.Sprintf("%s:%d", config.Config.Host, config.Config.Port)),
			iris.WithoutServerError(iris.ErrServerClosed),
			iris.WithOptimizations,
			iris.WithTimeFormat(time.RFC3339)); err != nil {
			fmt.Println(err)
		}
	}
}
